package com.zx.idc.backend.gui.api.management.infosecurity.activeresources.base.impl;

import com.zx.idc.backend.gui.api.management.infosecurity.activeresources.base.BaseActiveResourceService;
import com.zx.idc.common.util.JsonUtil;
import com.zx.idc.ds.upload.vo.UploadHotDomainVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import static com.zx.idc.common.attributes.SystemAttributes.WEB_SERVICE_FIND_DOMAIN_LIST_DIR;

@Service
@Transactional(rollbackFor = Exception.class)
public class FindDomainListServiceImpl extends BaseActiveResourceService<UploadHotDomainVo> {
    public FindDomainListServiceImpl() {
        super(WEB_SERVICE_FIND_DOMAIN_LIST_DIR);
    }

    @Override
    public List<UploadHotDomainVo> dataConversion(List<String> data, String houseId) {
        return data.stream().map(jsonString ->
            {
                UploadHotDomainVo uploadHotDomainVo = JsonUtil.read(jsonString, UploadHotDomainVo.class);
                if (uploadHotDomainVo != null) {
                    uploadHotDomainVo.setHouseId(houseId);
                }
                return uploadHotDomainVo;
            }
        ).filter(Objects::nonNull).collect(Collectors.toList());
    }
}
